/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.sys.service.support;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.utils.excel.ExcelExport;
import com.jeesite.modules.sys.dao.SystemDao;
import com.jeesite.modules.sys.entity.EmpUser;
import com.jeesite.modules.sys.entity.Employee;
import com.jeesite.modules.sys.service.EmpUserService;
import com.jeesite.modules.sys.service.SystemService;
import com.jeesite.modules.sys.utils.UserUtils;


/**
 * 行政区划Service
 * @author ThinkGem
 * @version 2014-8-19
 */
@Service
@Transactional(readOnly=true)
public class SystemServiceSupport implements SystemService {
	@Autowired
	private SystemDao systemDao;
	@Autowired
	private EmpUserService empUserService;
	@Override
	@Transactional(readOnly=false)
	public void remove(String userCode) {
		EmpUser empUser = new EmpUser();
		empUser.setUserCode(userCode);
		systemDao.deleteUser(empUser);
		Employee employee = new Employee();
		employee.setEmpCode(userCode);
		systemDao.deleteEmployee(employee);
		UserUtils.clearCache();
	}
	@Override
	public List<Map<String, Object>> totalTeacher(String officeCode) {
		return systemDao.totalTeacher(officeCode);
	}
	
	@Override
	public List<Map<String, Object>> total(String officeCode) {
		return systemDao.total(officeCode);
	}
	
	public List<Map<String,Object>> totalHighest(String officeCode){
		return systemDao.totalHighest(officeCode);
	}
	public List<Map<String,Object>> totalMentor(String officeCode){
		return systemDao.totalMentor(officeCode);
	}
	
	@Override
	public List<Map<String, Object>> nature() {
		return systemDao.nature();
	}
	@Override
	public List<Map<String, Object>> level() {
		return systemDao.level();
	}
	@Async
	public void exportAll(EmpUser empUser, Boolean isAll, String ctrlPermi,File file ,String fileName) throws IOException {
		empUser.getEmployee().getOffice().setIsQueryChildren(true);
		empUser.getEmployee().getCompany().setIsQueryChildren(true);
		if (!(isAll != null && isAll)){
			empUserService.addDataScopeFilter(empUser, ctrlPermi);
		}
		List<EmpUser> list = empUserService.findList(empUser);
		try(ExcelExport ee = new ExcelExport("教师数据", EmpUser.class)){
			FileOutputStream os=new FileOutputStream(new File(file,fileName));
			ee.setDataList(list).write(os);
			os.flush();
			os.close();
		}
	}
	@Override
	public List<Map<String, Object>> totalProfessional(String officeCode) {
		return systemDao.totalProfessional(officeCode);
	}
	@Override
	public List<Map<String, Object>> totalPolitical(String officeCode) {
		return systemDao.totalPolitical(officeCode);
	}
	@Override
	public List<Map<String, Object>> totalAgeGroup(String officeCode) {
		return systemDao.totalAgeGroup(officeCode);
	}
	@Override
	public List<Map<String, Object>> totalTalent(String officeCode) {
		return systemDao.totalTalent(officeCode);
	}

}
